﻿Imports System.ComponentModel
Imports Q2Q.Cues
Namespace UI
	Public Class CueMultiChannelSettings
		Implements INotifyPropertyChanged
		Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

		Private Sub RaisePropertyChanged(PropertyName As String)
			RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PropertyName))
		End Sub

#Region "Properties"

		''' <summary>
		''' Represents the Cue Property.
		''' </summary>
		''' <remarks></remarks>
		Public CueProperty As Cues.CueBase

		''' <summary>
		''' ReadOnly property to retrieve the details of the cue modifications performed in this window.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public ReadOnly Property Cue As Cues.CueBase
			Get
				Return CueProperty
			End Get
		End Property

		''' <summary>
		''' Represents the IsAudioCue Property.
		''' </summary>
		''' <remarks></remarks>
		Private IsAudioCueProperty As Boolean = False

		''' <summary>
		''' Returns true if the cue provided to examine the details of is an audio cue.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property IsAudioCue As Boolean
			Get
				Return IsAudioCueProperty
			End Get
			Set(value As Boolean)
				IsAudioCueProperty = value
				RaisePropertyChanged("IsAudioCue")
				If value = True Then
					IsTransportCue = False
				End If
			End Set
		End Property

		''' <summary>
		''' Represents the IsTransportCue property.
		''' </summary>
		''' <remarks></remarks>
		Private IsTransportCueProperty As Boolean = False

		''' <summary>
		''' Returns true if the cue provided to examine the details of is a transport cue.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property IsTransportCue As Boolean
			Get
				Return IsTransportCueProperty
			End Get
			Set(value As Boolean)
				IsTransportCueProperty = value
				RaisePropertyChanged("IsTransportCue")
				If value = True Then
					IsAudioCue = False
				End If
			End Set
		End Property

#End Region

		Public Sub New()

			' This call is required by the designer.
			InitializeComponent()

			' Add any initialization after the InitializeComponent() call.
			Dim a As New Cues.Audio
			CueProperty = a
			RaisePropertyChanged("Cue")
		End Sub

		''' <summary>
		''' Creates a new window, using the provided cue to show details.
		''' </summary>
		''' <param name="Cue"></param>
		''' <remarks></remarks>
		Public Sub New(Cue As Cues.CueBase)
			InitializeComponent()
			Select Case Cue.GetType()
				Case GetType(Cues.Audio)
					CueProperty = Cue
                    IsAudioCue = True
                Case GetType(Cues.Transport)
                    IsTransportCue = True
            End Select

            If CType(Cue, Cues.Audio).ChannelsList IsNot Nothing AndAlso CType(Cue, Cues.Audio).ChannelsList.Count >= 4 Then
                ce_01.IsChecked = CType(CueProperty, Cues.Audio).ChannelsList.Item(0).IsEnabled
                ce_23.IsChecked = CType(CueProperty, Cues.Audio).ChannelsList.Item(1).IsEnabled
                ce_45.IsChecked = CType(CueProperty, Cues.Audio).ChannelsList.Item(2).IsEnabled
                ce_67.IsChecked = CType(CueProperty, Cues.Audio).ChannelsList.Item(3).IsEnabled
            Else
                If My.Application.Show.ShowFile.Channel01Settings.IsEnabled AndAlso My.Application.Show.ShowFile.Channel01Settings.IsDefault Then
					ce_01.IsChecked = True
				End If
				If My.Application.Show.ShowFile.Channel23Settings.IsEnabled AndAlso My.Application.Show.ShowFile.Channel23Settings.IsDefault Then
					ce_23.IsChecked = True
				End If
				If My.Application.Show.ShowFile.Channel45Settings.IsEnabled AndAlso My.Application.Show.ShowFile.Channel45Settings.IsDefault Then
					ce_45.IsChecked = True
				End If
				If My.Application.Show.ShowFile.Channel67Settings.IsEnabled AndAlso My.Application.Show.ShowFile.Channel67Settings.IsDefault Then
					ce_67.IsChecked = True
				End If
			End If
		End Sub

		Private Sub CancelButton_Click(sender As Object, e As RoutedEventArgs) Handles CancelButton.Click
			Me.Close()
		End Sub

		Private Sub SaveButton_Click(sender As Object, e As RoutedEventArgs) Handles SaveButton.Click

			CType(CueProperty, Cues.Audio).ChannelsList = New List(Of Q2Q.Audio.Devices.DeviceChannel)
			Dim d0 As New Q2Q.Audio.Devices.DeviceChannel(0, Q2Q.Audio.Devices.DeviceChannelType.Stereo, False)
			d0.IsEnabled = ce_01.IsChecked
			CType(CueProperty, Cues.Audio).ChannelsList.Add(d0)

			Dim d1 As New Q2Q.Audio.Devices.DeviceChannel(1, Q2Q.Audio.Devices.DeviceChannelType.Stereo, False)
			d1.IsEnabled = ce_23.IsChecked
			CType(CueProperty, Cues.Audio).ChannelsList.Add(d1)

			Dim d2 As New Q2Q.Audio.Devices.DeviceChannel(2, Q2Q.Audio.Devices.DeviceChannelType.Stereo, False)
			d2.IsEnabled = ce_45.IsChecked
			CType(CueProperty, Cues.Audio).ChannelsList.Add(d2)

			Dim d3 As New Q2Q.Audio.Devices.DeviceChannel(3, Q2Q.Audio.Devices.DeviceChannelType.Stereo, False)
			d3.IsEnabled = ce_67.IsChecked
			CType(CueProperty, Cues.Audio).ChannelsList.Add(d3)

			If d0.IsEnabled = False AndAlso d1.IsEnabled = False AndAlso d2.IsEnabled = False AndAlso d3.IsEnabled = False Then
				CType(CueProperty, Cues.Audio).ChannelsList = Nothing
			End If

			Me.Close()
		End Sub
	End Class
End Namespace